package com.dk.mq;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dk.pojo.TOrder;
import com.dk.service.ITOrderService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@RocketMQMessageListener(consumerGroup = "my-group2",topic = "carOrder")
@Component
public class OrderMQ implements RocketMQListener<TOrder> {

    @Autowired
    private ITOrderService orderService;

    @Override
    public void onMessage(TOrder tOrder) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("out_trade_no",tOrder.getOutTradeNo());
        TOrder one = orderService.getOne(wrapper);
        if ("1".equals(one.getStatus())){
            orderService.removeById(one);
        }else {
            one.setStatus("2");
            orderService.updateById(one);
        }
    }
}
